{{include file="public/header.php"/}}

<ol class="breadcrumb">
	<li>
		<span class="glyphicon glyphicon-home"></span>
		<a href="{{U('Cms/Index/welcome')}}">首页</a>
	</li>
	<li>添加字段</li>
</ol>

<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<div class="alert alert-success" style="border:solid 1px #27ae60;">
				请仔细填写
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="main-box">
				<header class="main-box-header clearfix">
					<h2>添加字段</h2>
				</header>
				<div class="main-box-body clearfix ">
					<form class="form-horizontal" role="form" onsubmit="return save();">
						<input type="hidden" name="mid" value="{{$_GET['mid']}}">
						<table class="table table-bordered ">
							<tr>
								<th class="col-lg-4 text-right ">模型</th>
								<td>
									{{$model['model_name']}}
								</td>
							</tr>
							<tr>
								<th class="text-right">类型</th>
								<td>
									<div class="col-lg-3">
										<select class="form-control input-sm col-lg-2" id="field_type" name="field_type" onchange="changeFieldType(this)">
											<option value="input">单行文本</option>
											<option value="textarea">多行文本</option>
											<option value="number">数字</option>
											<option value="box">选项</option>
											<option value="editor">编辑器</option>
											<option value="image">图片</option>
											<option value="images">多图片</option>
											<option value="datetime">日期与时间</option>
											<option value="files">文件</option>
										</select>
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right ">表<br/><small>字段所在表</small>
								</th>
								<td>
									<div class="col-lg-5">
										<label>
											<input type="radio" name="table_type" value="1" checked=""> 主表
										</label>
										<label>
											<input type="radio" name="table_type" value="2"> 副表
										</label>
									</div>
									
								</td>
							</tr>
							<tr>
								<th class="text-right">字段标题<br/><small>例如：文章标题</small></th>
								<td>
									<label class="col-lg-4">
										<input type="text" class="form-control input-sm" name="title">
									</label>
								</td>
							</tr>
							<tr>
								<th class="text-right">字段名<br/><small>必须为英文小写字母</small></th>
								<td>
									<div class="col-lg-4">
										<input type="text"  class="form-control input-sm" name="field_name">
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right">字段提示</th>
								<td>
									<div class="col-lg-8">
										<textarea name="tips"  class="form-control" rows="5"></textarea>
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right">参数</th>
								<td id="field">
									
								</td>
							</tr>
							<tr>
								<th class="text-right">表单样式名<br/><small>定义表单的CSS样式名</small></th>
								<td>
									<div class="col-lg-5">
										<input type="text" class="form-control input-sm" name="css">
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right">字符长度取值范围
									<br/><small>系统将在表单提交时检测数据长度范围，如果不想限制长度请留空</small>
								</th>
								<td class="form-horizontal">
									<div class="form-group">
										<label for="" class="col-lg-1 text-right">
											最小值:
										</label>
										<div class="col-lg-2">
											<input type="text" class="form-control input-sm" name="minlength">
										</div>
										<label for="" class="col-lg-1 text-right">
											最大值:
										</label>
										<div class="col-sm-2">
											<input type="text" class="form-control input-sm" name="maxlength">
										</div>
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right">表单验证
									<br/><small>系统将通过此正则校验表单提交的数据合法性，如果不想校验数据请留空</small>
								</th>
								<td>
									<div class="col-sm-5">
										<input type="text" class="form-control input-sm" name="validate">
									</div>
									<div class="col-sm-2">
										<select id="field_check" class="form-control input-sm">
											<option value="">常用正则</option>
											<option value="/^[0-9.-]+$/">数字</option>
											<option value="/^[0-9-]+$/">整数</option>
											<option value="/^[a-z]+$/i">字母</option>
											<option value="/^[0-9a-z]+$/i">数字+字母</option>
											<option value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
											<option value="/^[0-9]{5,20}$/">QQ</option>
											<option value="/^http:\/\//">超级链接</option>
											<option value="/^(1)[0-9]{10}$/">手机号码</option>
											<option value="/^[0-9-]{6,13}$/">电话号码</option>
											<option value="/^[0-9]{6}$/">邮政编码</option>
										</select>
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right">必须输入
								</th>
								<td>
									<label>
										<input type="radio" name="required" value="1"> 是
									</label>
									<label>
										<input type="radio" name="required" checked="" value="0"> 否
									</label>
								</td>
							</tr>
							<tr>
								<th class="text-right">错误提示<br/>
									<small>输入内容不正确时的提示信息</small>
								</th>
								<td>
									<div class="col-lg-5">
										<input type="text" class="form-control input-sm" name="error">
									</div>
								</td>
							</tr>
							<tr>
								<th class="text-right">值唯一</th>
								<td>
									<label>
										<input type="radio" name="isunique" value="1"> 是
									</label>
									<label>
										<input type="radio" name="isunique" checked="" value="0"> 否
									</label>
								</td>
							</tr>
							<tr>
								<th class="text-right">作为基本信息</th>
								<td>
									<label>
										<input type="radio" name="isbase" checked="" value="1"> 是
									</label>
									<label>
										<input type="radio" name="isbase" value="0"> 否
									</label>
								</td>
							</tr>
							<tr>
								<th class="text-right">作为搜索条件</th>
								<td>
									<label>
										<input type="radio" name="issearch" value="1"> 是
									</label>
									<label>
										<input type="radio" name="issearch" checked="" value="0"> 否
									</label>
								</td>
							</tr>
							<tr>
								<th class="text-right">在前台投稿中显示</th>
								<td>
									<label>
										<input type="radio" name="isadd" value="1"> 是
									</label>
									<label>
										<input type="radio" name="isadd" checked="" value="0"> 否
									</label>
								</td>
							</tr>
						</table>
						<div class="col-lg-offset-4">
							<input type="submit" class="btn btn-primary" value="添加字段">
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
{{include file="public/footer.php"/}}
<style type="text/css">
	small{color:#999;}
	th{
		background: #f9f9f9;
	}
	td{
		background: #f3f3f3;
	}
</style>
<script>
	//选择表单类型
	function changeFieldType(obj)
	{
		$.get("{{U('getAddFieldView')}}",{type:$(obj).val()},function(html)
		{
			$("#field").html(html);
		});
	}
	$("#field_type").trigger("change");

	//删除菜单
	function save()
	{
		$.ajax({
			url:"/cms/field",
			data:$('form').serialize(),
			type:'POST',
			dataType:'JSON',
			success:function(result)
			{
				if(result.code==0)
				{
					dialog(result.message,'success',1000,function()
					{
						location.href="/cms/field?mid={{$_GET['mid']}}"
					});
				}
				else
				{
					dialog(result.message,'error',1000);    
				}
			}
		})
		return false;
	}
</script>